package com.dzm.content.controller.admin;

import com.dzm.constants.ClientConstant;
import com.dzm.content.service.TokenService;
import com.dzm.content.service.UserService;
import com.dzm.content.vo.LoginVo;
import com.dzm.to.LoginUser;
import com.dzm.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 作者：Dzm
 * 时间：2024-09-13-19:24
 * 功能：
 */

@RestController
@RequestMapping("/admin/auth")
public class AuthController {

    @Autowired
    private UserService userService;

    @Autowired
    private TokenService tokenService;

    @PostMapping("/login")
    public R login(@RequestBody LoginVo vo) {
        LoginUser loginUser = userService.getLoginUser(vo);

        Map<String, Object> map = tokenService.createToken(loginUser);

        return R.ok().data(map);
    }

    @GetMapping("/info")
    public R info(@RequestHeader(ClientConstant.CLIENT_TOKEN_NAME) String  authorization) {
        Map<String, Object> map = userService.getUserInfo(authorization);

        return R.ok().data(map);
    }
}
